package org.hk.basic.studyspring.aop;

import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.DefaultPointcutAdvisor;

public class House {
    public static void main(String[] args) {
        //有一个不洗手的原生小孩
        Children children = new Children();
        //准备一个改造方案,改造方案 由拦击标准pointcut 和 附加处理通知 advice组成
        DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor();//空方案
        DefaultPointcutAdvisor advisor2 = new DefaultPointcutAdvisor();//空方案
        EatPointcut pointcut  =  new EatPointcut();//准备好拦截标准
        WashHandAdvice washHandAdvice = new WashHandAdvice();//附加的洗手逻辑
        CleanMouthAdvice cleanMouthAdvice = new CleanMouthAdvice();
        advisor.setPointcut(pointcut);
        advisor.setAdvice(washHandAdvice);

       advisor2.setPointcut(pointcut);//吃完擦嘴的方案也是一样的拦截标准
        advisor2.setAdvice(cleanMouthAdvice);


        ProxyFactory mother = new ProxyFactory();//准备加工厂,母亲监督员
        mother.setTarget(children);//小孩送入工厂，母亲控制小孩
        //mother.addAdvisor(advisor);//方案送入工厂，母亲准备方案
       // mother.addAdvisor(advisor2);
        Children  newChildren = (Children) mother.getProxy();//得到代理对象，得到改造后的产品
        newChildren.eatFruit();
        //children.eatFruit();
        //System.out.println(children.getHandState());
        newChildren.watchTV();
        //System.out.println(children.getHandState());
        newChildren.eatSugar();
       // System.out.println(children);
        //System.out.println(newChildren);
    }

}
